package com.wkk.websocket.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wkk.annotation.AutoLog;
import com.wkk.log.common.LogConstant;
import com.wkk.vo.Result;
import com.wkk.websocket.dto.AnnouncementHistoryDto;
import com.wkk.websocket.dto.MessageSendDto;
import com.wkk.websocket.group.GroupChat;
import com.wkk.websocket.group.SingleChat;
import com.wkk.websocket.service.AnnouncementService;
import com.wkk.websocket.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * @author : WangKeKe
 * @date : 2020/9/30 14:05
 * Description : 消息控制类
 */

@RestController
@Slf4j
@Api(tags = "RESTFUL-用户-消息接口")
@RequestMapping("/msg/user")
public class MsgController {

    @Autowired
    private AnnouncementService announcementService;

    @Autowired
    private MessageService messageService;


    @AutoLog(description = LogConstant.ROLE_NAME_USER + "-大喇叭使用")
    @ApiImplicitParam(name = "content", value = "消息内容不能为空,且不能超过200个字", required = true)
    @ApiOperation("发送大喇叭")
    @PostMapping("/sendMegaphone/{content}")
    public Result<String> sendMegaphone(@PathVariable("content") String content) {
        return announcementService.releaseAnnouncement(content) ?
                Result.ok("喇叭使用成功") : Result.error("喇叭使用失败");
    }

    @AutoLog(description = LogConstant.ROLE_NAME_ALL + "-历史公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码不能小于1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数不能小于1", required = true),
    })
    @ApiOperation("历史公告")
    @GetMapping("/announcement/history/{pageNo}/{pageSize}")
    public Result<Page<AnnouncementHistoryDto>> queryPage(@PathVariable Integer pageNo,
                                                          @PathVariable Integer pageSize) {
        return Result.ok(announcementService.queryPage(pageNo, pageSize));
    }

    @AutoLog(description = LogConstant.ROLE_NAME_USER + "-私发消息")
    @ApiOperation("私发消息")
    @PostMapping("/single")
    public Result<String> sendSingleChat(@RequestBody @Validated(SingleChat.class) MessageSendDto messageSendDto) {
        return messageService.sendMsg(messageSendDto) ? Result.ok("私发消息成功") : Result.error("私发消息失败");
    }

    // 消息列表

    // 单人消息详情

    // 未查看消息

    @AutoLog(description = LogConstant.ROLE_NAME_USER + "-群发消息")
    @ApiOperation("群发消息")
    @PostMapping("/group")
    public Result<String> sendGroupChat(@RequestBody @Validated({GroupChat.class}) MessageSendDto messageSendDto) {
        return messageService.sendMsg(messageSendDto) ? Result.ok("群发消息成功") : Result.error("群发消息失败");
    }
}
